<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        // ES6 允许按照一定模式，从数组和对象中提取值，对变量进行赋值，这被称为解构
        // 解构赋值：根据结构解析数据，并进行赋值操作

        // 1.基本用法(完全解构)
        let arr=["达梓寒","楚过寒","杨过"];
        let [a,b,c]=arr;
        console.log(a,b,c);

        // 2.不完全解构
        let [,,d,e]=["胡歌","包永强","王一博","达梓寒"];
        console.log(d,e);

       /*  3.剩余解构，格式: ...变量名
            剩余解构只对没有被取值的剩余的数据进行数组包装
            剩余解构的语法必须出现在解构的模式的最后一位 */

        let [aa,...bb]=["杨幂","赵露思","lili","lucy","赵丽颖"];
        console.log(aa);
        console.log(bb);

        // 4.模式匹配失败
        let [f]=[];
        console.log(f);

        // 5.多维数组的嵌套解构
        let [,temp1,,[,temp2]]=["alice","tom","cici",["huahua","xiaoming","hello"]];
        console.log(temp1,temp2);

        let x=3;
        let y=4;
        [x,y]=[y,x];
        console.log(x,y);
    </script>
</head>
<body>
    
</body>
</html>